package androidlab.sprintingsquirrel.game;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import androidlab.sprintingsquirrel.BaseScene;
import androidlab.sprintingsquirrel.ResourceManager;
import androidlab.sprintingsquirrel.SceneManager;


public class GameOverWindow extends Sprite {

	private Sprite restartLevelButton;
	private BaseScene scene;
	    
	public GameOverWindow(VertexBufferObjectManager pSpriteVertexBufferObject, BaseScene scene) {
		super(0, 0, 705, 405, ResourceManager.getInstance().gameOverWindowTR, pSpriteVertexBufferObject);
		this.scene = scene;
	    attachRestartButton(pSpriteVertexBufferObject);
	}
	    
	private void attachRestartButton(VertexBufferObjectManager pSpriteVertexBufferObject) {
	    	
		restartLevelButton = new Sprite(0, 0, ResourceManager.getInstance().restartButtonTR, pSpriteVertexBufferObject){
			@Override
			public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
				SceneManager.getInstance().createGameScene(ResourceManager.getInstance().getLevel());
				scene.disposeScene();
				ResourceManager.getInstance().loadLoadingTextures();
				return false;
			}
		};
		
		restartLevelButton.setScale(0.3f);
		attachChild(restartLevelButton);
		scene.registerTouchArea(restartLevelButton);
		    	
	}

	public void display(Scene scene, Camera camera) {
	    	
		setPosition(camera.getCenterX()-ResourceManager.getInstance().gameOverWindowTR.getWidth()/2, camera.getCenterY()-ResourceManager.getInstance().gameOverWindowTR.getHeight()/2);
		restartLevelButton.setPosition(515, 215);
		scene.attachChild(this);
	}
	
}
